// localLifePackage/pages/writeCodeDetail/writeCodeDetail.js
var common = require("../../../common/common.js").common;

const app = getApp();

Page({
    /**
   * 页面的初始数据
   */
    data: {
        title: "订单详情",
        detail: {},
        componentStyle: {
            navigationTitle: "订单详情",
            goBack: true
        }
    },
    /**
   * 生命周期函数--监听页面加载
   */
    onLoad: function(options) {
        this.getBase();
        this.setData({
            order_sn: options.order_sn,
            domain: app.globalData.domain.slice(0, -10)
        });
        this.getData();
        this.getCodeQr();
    },
    /**
   * 生命周期函数--监听页面初次渲染完成
   */
    onReady: function() {},
    /**
   * 生命周期函数--监听页面显示
   */
    onShow: function() {},
    /**
   * 生命周期函数--监听页面隐藏
   */
    onHide: function() {},
    /**
   * 生命周期函数--监听页面卸载
   */
    onUnload: function() {},
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
    onPullDownRefresh: function() {},
    /**
   * 页面上拉触底事件的处理函数
   */
    onReachBottom: function() {},
    /**
   * 用户点击右上角分享
   */
    onShareAppMessage: function() {},
    getBase: function() {
        var that = this;
        common.request({
            endpoint: "set/app_base",
            method: "get",
            data: {},
            success: res => {
                wx.setNavigationBarColor({
                    frontColor: "#ffffff",
                    backgroundColor: res.extra.color_main
                });
                var componentStyle = that.data.componentStyle;
                that.setData({
                    componentStyle: {
                        ...componentStyle,
                        color_minor: !res.extra.color_main ? "#FE513B" : res.extra.color_main,
                        color_minor: !res.extra.color_minor ? "#FE513B" : res.extra.color_minor
                    },
                    timeStyle: {
                        height: 32,
                        mainColor: res.extra.color_main
                    },
                    color_main: res.extra.color_main,
                    color_minor: res.extra.color_minor,
                    apptitle: res.extra.title,
                    style: res.extra.style
                });
            }
        });
    },
    getData: function() {
        let that = this;
        common.request({
            endpoint: "Localbusiness/order/order-detail",
            method: "post",
            data: {
                order_sn: that.data.order_sn
            },
            success: res => {
                if (res.extra.product_content.using_expire_in) {
                    res.extra.product_content.using_expire_in = res.extra.product_content.using_expire_in.split(",").join("~");
                } else {
                    res.extra.product_content.using_expire_in = "永久有效";
                }
                if (res.extra.status == 4 || res.extra.status == 5) {
                    res.extra.write_off_code.map(v => {
                        v.used = "1";
                    });
                }
                that.setData({
                    detail: res.extra
                });
            }
        });
    },
    getCodeQr: function() {
        let that = this;
        common.request({
            endpoint: "Localbusiness/order/order-detail",
            method: "post",
            data: {
                page: "/pages/index/index",
                code: "",
                order_sn: that.data.order_sn
            },
            success: res => {}
        });
    }
});